package org.jeecg.modules.job.wms.service.impl;

import org.jeecg.modules.job.utils.pdf.FileInfo;
import org.jeecg.modules.job.utils.pdf.PdfUtils;
import org.jeecg.modules.job.wms.entity.WmsResume;
import org.jeecg.modules.job.wms.entity.WmsResumeFile;
import org.jeecg.modules.job.wms.mapper.WmsResumeFileMapper;
import org.jeecg.modules.job.wms.service.IWmsResumeFileService;
import org.jeecg.modules.job.wms.service.IWmsResumeService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 简历附件
 * @Author: jeecg-boot
 * @Date:   2022-12-18
 * @Version: V1.0
 */
@Service
public class WmsResumeFileServiceImpl extends ServiceImpl<WmsResumeFileMapper, WmsResumeFile> implements IWmsResumeFileService {
	
	@Autowired
	private WmsResumeFileMapper wmsResumeFileMapper;
	@Resource
	private IWmsResumeService resumeService;
	@Autowired
	private FreeMarkerConfigurer configurer;
	
	@Override
	public List<WmsResumeFile> selectByMainId(String mainId) {
		return wmsResumeFileMapper.selectByMainId(mainId);
	}

	@Override
	public String exportWordFile(HttpServletRequest request, WmsResume resumeParam) throws Exception {
		WmsResume resumeResult=resumeService.getResume(resumeParam);
		// 构造freemarker模板引擎参数,listVars.size()个数对应pdf页数
		List<Map<String,Object>> listVars = new ArrayList<>();
		Map<String,Object> variables = new HashMap<>();
		listVars.add(variables);
		FileInfo fileInfo= PdfUtils.createPdfFile(configurer,"pdfPage.ftl",listVars,request,resumeResult);
		//保存到简历附件
		WmsResumeFile resumeFileParam=new WmsResumeFile();
		resumeFileParam.setFileExt(fileInfo.getType());
		resumeFileParam.setFileName(fileInfo.getName());
		resumeFileParam.setFileSize(fileInfo.getSize());
		resumeFileParam.setFileUrl(fileInfo.getUrl());
		resumeFileParam.setMemberId(resumeParam.getMemberId());
		this.save(resumeFileParam);
		return fileInfo.getUrl();
	}
}
